/*
 * 添加部门信息交易
 * 参数   交易码：trancode=14122
 * 
 */

package org.ccams.tran;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.ccams.domain.TDept;
/**
 * 添加部门信息交易
 * @author liuguangshuai@gmail.com
 * @系统名称：定制化辅助生成制造系统
 * @时间：Sep 18, 2008
 */
public class Tran14122 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String deptName = (String) request.getParameter("deptName");
		String smallName = (String) request.getParameter("smallName");
		String deptAddress = (String) request.getParameter("deptAddress");
		Long mainPid = Long.parseLong(request.getParameter("mainPid"));
		deptName = (deptName != null) ? deptName : "";
		smallName = (smallName != null) ? smallName : "";
		deptAddress = (deptAddress != null) ? deptAddress : "";
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		boolean success = false;
		String message = "";
		TDept t = new TDept();
		t.setDeptAddress(deptAddress);
		t.setDeptName(deptName);
		t.setSmallName(smallName);
		t.setMainPid(mainPid);
		t.setValid(0);
		int i = getCcamsService().getTdeptDao().insert(t);
		if (i == 1) {
			success = true;
			message = "部门添加成功";
		} else {
			success = false;
			message = "部门添加失败";
		}
		jsonMap.put("success", success);
		jsonMap.put("message", message);
		json.putAll(jsonMap);
	}
}
